<template>
	<view class="fenxiao_index" :data-theme="themeStyle">
		<block v-if="info.fenxiao_name">
			<view class="head_view color-base-bg">
				<!-- :style="{backgroundImage:'url('+$util.img('public/uniapp/h5/fenxiao/fenxiao_index_headbg_icon.png')+')'}" -->
				<view class="info_v">
					<view class="info_view">
						<image class="info_img"
							:src="info.headimg ? $util.img(info.headimg) : $util.getDefaultImage().default_headimg"
							@error="info.headimg = $util.getDefaultImage().default_headimg" mode="aspectFill"></image>
						<view class="in_cont">
							<view class="name_level">
								<view class="in_name">{{info.fenxiao_name}}</view>
							</view>
							 <view class="in_level" @click="$util.redirectTo('/otherpages/fenxiao/level/level')">
							 	{{ info.level_name }}
							 </view>
							<!-- <view class="referees_view">邀请码：{{ info.invite_code }}<text class="referees_copy"
									@click="$util.copy( info.invite_code)">复制</text></view> -->
							<!-- <view class="referees_view">推荐人：{{ info.parent_name ? info.parent_name : '无' }}</view> -->
						</view>
					</view>
					<image class="code_img" :src="$util.img('public/uniapp/h5/fenxiao/fenxiao_index_code_icon.png')"
						mode="aspectFill" @click="$util.redirectTo('/otherpages/fenxiao/promote_code/promote_code')">
					</image>
				</view>
				<view class="my_earnings">
					<view class="earning_t_view">
						<view class="earning_title">我的消费券</view>
						<view class="chack_view" @click="$util.redirectTo('/otherpages/member/balance_detail/balance_detail')">
							<view class="chack_t">查看详情</view>
							<image :src="$util.img('public/uniapp/h5/fenxiao/fenxiao_index_detail_right_icon.png')"
								mode="aspectFill"></image>
						</view>
					</view>
					<view class="earnings_list">
						<view class="earnings_item" v-for="(item,index) in earnings" :key="index"
							@click="$util.redirectTo(item.router)">
							<view class="earn_num">{{item.num}}</view>
							<view class="earn_name">{{item.name}}</view>
						</view>
					</view>
				</view>
			</view>
			<view class="embodiment_view">
				<view class="embodiment_title">我的商家</view>
				<view class="embodiment_content">
					<view class="embodiment_list">
						<view class="embodiment_item" v-for="(item,index) in embodiments" :key="index"
							@click="$util.redirectTo('/businesscenter/store-manage')">
							<view class="embodiment_num">{{item.num}}</view>
							<view class="embodiment_name">{{item.name}}</view>
						</view>
					</view>
					<view class="go_embodiment_view">
						<view class="embodiment_line"></view>
						<view class="embodimentBut"
							@click="$util.redirectTo('/businesscenter/invite-store')">
							<image :src="$util.img('public/uniapp/h5/fenxiao/fenxiao_index_ embodiment_but_icon.png')"
								mode="aspectFill"></image>
							<view class="embodimentBut_title">去推广</view>
						</view>
					</view>
				</view>
			</view>
			
			<view class="distribution_team"
				@click="$util.redirectTo('/otherpages/fenxiao/lockusers/lockusers?toolsTpye=2')">
				<view class="logo_view">
					<image :src="$util.img('public/uniapp/h5/fenxiao/distribution_team_logo_icon.png')"></image>
					<view class="logo_name">推广团队</view>
				</view>
				<view class="distribution_list">
					<view class="distribution_item" v-for="(item,index) in distribution_teams" :key="index">
						<view class="item_num">{{item.num}}</view>
						<view class="item_name">{{item.name}}</view>
					</view>
				</view>
			</view>
			<!-- <view v-if="basicsConfig.level > 2" class="distribution_team gray"
				@click="$util.redirectTo('/otherpages/fenxiao/fission_member/fission_member')">
				<view class="logo_view">
					<image :src="$util.img('public/uniapp/h5/fenxiao/lock_use_icon.png')"></image>
					<view class="logo_name lock_use">裂变团队</view>
				</view>
				<view class="distribution_list">
					<view class="distribution_item" v-for="(item,index) in lock_uses" :key="index">
						<view class="item_num lock_num">{{item.num}}</view>
						<view class="item_name lock_name">{{item.name}}</view>
					</view>
				</view>
			</view> -->

			<view class="tools_view">
				<view class="tool_t">常用工具</view>
				<view class="tool_content">
					<view class="tool_item" v-for="(item,index) in tools" :key="index" @click="toToolsEvent(item)">
						<image :src="item.url"></image>
						<view class="tool_name">{{item.name}}</view>
					</view>
				</view>
			</view>
		</block>
		<block v-else>
			<view class="empty">
				<image :src="$util.img('upload/uniapp/fenxiao/index/no-fenxiao.png')" mode="widthFix"></image>
				<text>您还不是，请先提交申请</text>
				<view @click="$util.redirectTo('/otherpages/fenxiao/apply/apply')" class="color-base-bg">立即加入</view>
			</view>
		</block>
		<loading-cover ref="loadingCover"></loading-cover>
	</view>
</template>

<script>
	import globalConfig from '@/common/js/golbalConfig.js';
	import fenxiaoWords from '@/common/js/fenxiao-words.js';
	export default {
		mixins: [globalConfig, fenxiaoWords],
		data() {
			return {
				info: {
					fenxiao_name: '1'
				},
				earnings: [{
						name: '今日',
						num: 0,
						router: '/otherpages/fenxiao/order/order'
					},
					{
						name: '结算中',
						num: 0,
						router: '/otherpages/fenxiao/order/order'
					},
					{
						name: '已结算',
						num: 0,
						router: '/otherpages/member/balance_detail/balance_detail'
					},
					{
						name: '累计',
						num: 0,
						router: '/otherpages/fenxiao/order/order'
					}
				],
				embodiments: [{
					name: '总人数',
					num: 0,
				},
				{
					name: '今日新增',
					num: 0,
				},
				{
					name: '7日新增',
					num: 0,
				}],
				distribution_teams: [{
						name: '总人数',
						num: 0
					},
					{
						name: '今日新增',
						num: 0
					},
					{
						name: '7日新增',
						num: 0
					}
				],
				lock_uses: [{
						name: '总人数',
						num: 0
					},
					{
						name: '今日新增',
						num: 0
					},
					{
						name: '7日新增',
						num: 0
					}
				],
				rankingLists: [], //四五名
				top_three: [], //前三名
				tools: [],
				basicsConfig: {},
			}
		},
		async onShow() {
			await this.getFenxiaoWrods();
			// 刷新多语言
			this.$langConfig.refresh();
			if (!this.addonIsExit.fenxiao) {
				this.$util.showToast({
					title: '分销未开启',
					mask: true
				});
				setTimeout(() => {
					this.$util.redirectTo('/pages/index/index/index', {}, 'redirectTo');
				}, 1000);
			} else {
				this.tools = [{
						name: '商家管理',
						url: this.$util.img('public/uniapp/h5/fenxiao/tools_withdrawal_icon.png'),
						router: '/businesscenter/store-manage',
						toolsTpye: 0
					},
					{
						name: '邀请商家',
						url: this.$util.img('public/uniapp/h5/fenxiao/tools_withdrawal_detail_icon.png'),
						router: '/businesscenter/invite-store',
						toolsTpye: 0
					},
					{
						name: '业绩订单',
						url: this.$util.img('public/uniapp/h5/fenxiao/tools_distribution_order_icon.png'),
						router: '/otherpages/fenxiao/order/order',
						toolsTpye: 0
					},
					{
						name: '锁定用户',
						url: this.$util.img('public/uniapp/h5/fenxiao/tools_distribution_team_icon.png'),
						router: '/otherpages/fenxiao/lockusers/lockusers?toolsTpye=2',
						toolsTpye: 0
					},
					{
						name: '区域用户',
						url: this.$util.img('public/uniapp/h5/fenxiao/tools_lock_user_icon.png'),
						router: '/otherpages/fenxiao/my-customer/my-customer',
						toolsTpye: 1
					},
					{
						name: '业绩统计',
						url: this.$util.img('public/uniapp/h5/fenxiao/tools_ranking_icon.png'),
						router: '/otherpages/fenxiao/relation/relation',
						toolsTpye: 0
					},
					{
						name: '收益明细',
						url: this.$util.img('public/uniapp/h5/fenxiao/tools_returns_detailed_icon.png'),
						router: '/otherpages/member/balance_detail/balance_detail',
						toolsTpye: 0
					},
					// {
					// 	name: '分红中心',
					// 	url: this.$util.img('public/uniapp/h5/fenxiao/tools_fission_reward_icon.png'),
					// 	router: '/xxjk/bonus/bonusCenter',
					// 	toolsTpye: 0
					// }
				];
				this.getFenxiaoBasicsConfig();
				this.$langConfig.title(this.fenxiaoWords.concept + '中心');
				this.getTeamData();
				if (uni.getStorageSync('token')) {
					this.getFenxiaoDetail();
				} else {
					this.$util.redirectTo(
						'/otherpages/login/login/login', {
							back: '/otherpages/fenxiao/index/index'
						},
						'redirectTo'
					);
				}
			}
		},
		methods: {
			/**
			 * 获取分销基本配置
			 */
			getFenxiaoBasicsConfig() {
				this.$api.sendRequest({
					url: '/fenxiao/api/config/basics',
					data: {},
					success: res => {
						if (res.code >= 0 && res.data) {
							this.basicsConfig = res.data;
							if (this.basicsConfig.level > 2) {
								this.tools = this.tools.concat([{
										name: '裂变奖励',
										url: this.$util.img(
											'public/uniapp/h5/fenxiao/tools_fenhong_icon.png'),
										router: '/otherpages/fenxiao/fission_reward_details/fission_reward_details',
										toolsTpye: 0
									},
									{
										name: '裂变团队',
										url: this.$util.img(
											'public/uniapp/h5/fenxiao/tools_fission_member_icon.png'
										),
										router: '/otherpages/fenxiao/fission_member/fission_member',
										toolsTpye: 0
									}
								]);
							}
						}
					}
				});
			},
			/* 常用工具跳转 */
			toToolsEvent(item) {
				this.$util.redirectTo(item.router, {
					toolsTpye: item.toolsTpye
				})
			},
			/* 获取分销商信息 */
			getFenxiaoDetail() {
				this.$api.sendRequest({
					url: '/fenxiao/api/fenxiao/detail',
					success: res => {
						if (res.data) {
							if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
							this.info = res.data;

							/* 我的收益 */
							this.earnings[0].num = res.data.today_commission
							this.earnings[1].num = res.data.process_commission
							this.earnings[2].num = res.data.total_commission
							this.earnings[3].num = res.data.all_commission

							/* 我的商家 */
							this.embodiments[0].num = res.data.count_shop_num
							this.embodiments[1].num = res.data.day_shop_num
							this.embodiments[2].num = res.data.seven_shop_num
						} else {
							this.$util.redirectTo('/otherpages/fenxiao/apply/apply', {}, 'redirectTo');
						}
					},
					fail: res => {
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					}
				});
			},
			getTeamData() {
				this.$api.sendRequest({
					url: '/fenxiao/api/fenxiao/fenxiaoTeam',
					data: {},
					success: res => {
						if (res.data) {
							this.distribution_teams[0].num = res.data.fenxiao.team
							this.distribution_teams[1].num = res.data.fenxiao.day
							this.distribution_teams[2].num = res.data.fenxiao.week

							this.lock_uses[0].num = res.data.member.total
							this.lock_uses[1].num = res.data.member.today
							this.lock_uses[2].num = res.data.member.seven
						}
					}
				})
			}

		}
	}
</script>

<style lang="scss">
	.fenxiao_index {
		.head_view {
			height: 516rpx;
			background-size: cover;
			padding: 71rpx 30rpx 0rpx 30rpx;

			.info_v {
				display: flex;
				align-items: center;
				justify-content: space-between;

				.info_view {
					display: flex;
					align-items: center;

					.info_img {
						width: 118rpx;
						height: 118rpx;
						border-radius: 59rpx;
					}

					.in_cont {
						margin-left: 20rpx;

						.name_level {
							display: flex;
							align-items: center;

							.in_name {
								font-size: 32rpx;
								font-family: PingFangSC-Medium, PingFang SC;
								font-weight: 500;
								// color: #303133;
								color: #FFFFFF;
								line-height: 46rpx;
							}
							
						}
						
						.in_level {
							// margin-left: 10rpx;
							margin-top: 10rpx;
							padding: 4rpx 10rpx;
							border-radius: 18rpx;
							background: linear-gradient(135deg, rgba(199, 159, 69, 0.15) 0%, rgba(199, 159, 69, 0.5) 100%);
							font-size: 22rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							// color: #784612;
							color: #FFFFFF;
							line-height: 30rpx;
							display: flex;
							justify-content: center;
							align-items: center;
						}

						.referees_view {
							margin-top: 10rpx;
							font-size: 24rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							// color: #666666;
							opacity: 0.5;
							color: #FFFFFF;
							line-height: 34rpx;

							.referees_copy {
								margin-left: 10rpx;
								color: #e7e525;
								font-weight: 600;
							}
						}
					}
				}

				.code_img {
					width: 48rpx;
					height: 48rpx;
					opacity: 0.5;
				}
			}

			.my_earnings {
				margin-top: 60rpx;
				padding: 30rpx;
				background: #fff;
				border-radius: 16rpx;

				.earning_t_view {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.earning_title {
						font-size: 32rpx;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 500;
						color: #303133;
						line-height: 34rpx;
					}

					.chack_view {
						display: flex;
						align-items: center;

						.chack_t {
							font-size: 24rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #909399;
							line-height: 33rpx;
						}

						image {
							width: 32rpx;
							height: 32rpx;
						}
					}
				}

				.earnings_list {
					margin-top: 30rpx;
					display: flex;

					.earnings_item {
						display: flex;
						flex-direction: column;
						align-items: center;
						width: 25%;

						.earn_num {
							font-size: 32rpx;
							font-family: PingFangSC-Medium, PingFang SC;
							font-weight: 500;
							color: #303133;
							line-height: 45rpx;
						}

						.earn_name {
							margin-top: 8rpx;
							font-size: 24rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #909399;
							line-height: 34rpx;

						}
					}
				}
			}
		}

		.embodiment_view {
			margin: -106rpx 30rpx 0rpx 30rpx;
			background: #fff;
			border-radius: 16rpx;
			padding: 30rpx;

			.embodiment_title {
				font-size: 32rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #303133;
				line-height: 34rpx;
			}

			.embodiment_content {
				display: flex;
				margin-top: 30rpx;

				.embodiment_list {
					width: 75%;
					display: flex;

					.embodiment_item {
						width: 33%;
						display: flex;
						justify-content: center;
						align-items: center;
						flex-direction: column;

						.embodiment_num {
							font-size: 32rpx;
							font-family: PingFangSC-Medium, PingFang SC;
							font-weight: 500;
							color: #303133;
							line-height: 45rpx;
						}

						.embodiment_name {
							font-size: 24rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #909399;
							line-height: 34rpx;
						}
					}
				}

				.go_embodiment_view {
					width: 25%;
					display: flex;
					align-items: center;

					.embodiment_line {
						margin-left: 20rpx;
						margin-right: 40rpx;
						width: 1rpx;
						height: 74rpx;
						background: #EBEBEB;
					}

					.embodimentBut {
						display: flex;
						justify-content: center;
						align-items: center;
						flex-direction: column;

						image {
							width: 48rpx;
							height: 48rpx;
						}

						.embodimentBut_title {
							font-size: 24rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #C79F45;
							line-height: 33rpx;
						}
					}
				}
			}
		}

		.distribution_team {
			margin: 20rpx 30rpx;
			border-radius: 16rpx;
			background: linear-gradient(135deg, rgba(199, 159, 69, 0.15) 0%, rgba(199, 159, 69, 0.5) 100%);
			display: flex;
			align-items: center;
			justify-content: center;
			padding: 40rpx 0rpx;

			.logo_view {
				width: 25%;
				display: flex;
				align-items: center;
				justify-content: center;
				flex-direction: column;

				image {
					margin-top: -16rpx;
					width: 64rpx;
					height: 64rpx;
				}

				.logo_name {
					margin-top: 4rpx;
					font-size: 28rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #784612;
					line-height: 34rpx;
				}

				.lock_use {
					color: #6D7597;
				}
			}

			.distribution_list {
				width: 75%;
				display: flex;
				align-items: center;
				justify-content: center;

				.distribution_item {
					width: 33%;
					display: flex;
					align-items: center;
					justify-content: center;
					flex-direction: column;

					.item_num {
						font-size: 32rpx;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 500;
						color: #784612;
						line-height: 45rpx;
					}

					.lock_num {
						color: #6D7597;
					}

					.item_name {
						margin-top: 8rpx;
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: rgba(120, 70, 18, 0.7);
						line-height: 34rpx;
					}

					.lock_name {
						color: rgba(109, 117, 151, 0.75);
					}
				}
			}
		}

		.gray {
			background: linear-gradient(135deg, rgba(109, 117, 151, 0.15) 0%, rgba(109, 117, 151, 0.5) 100%);
		}

		.ranking_view {
			margin: 20rpx 30rpx;
			height: 590rpx;
			background-size: cover;
			padding: 30rpx;

			.ranking_head {
				display: flex;
				justify-content: space-between;

				.ranking_head_t {
					font-size: 32rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #784612;
					line-height: 45rpx;
				}

				.looks_view {
					display: flex;

					.looks_name {
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #784612;
						line-height: 33rpx;
					}

					image {
						width: 32rpx;
						height: 32rpx;
					}
				}
			}

			.ranking_content {
				height: 494rpx;
				background-size: cover;

				.r_view {
					margin-top: 34rpx;
					display: flex;

					.ranking_item {
						width: 33%;
						// padding-bottom: 30rpx;
					}

					.one {
						display: flex;
						align-items: center;
						flex-direction: column;

						.one_img {
							margin-top: 40rpx;
							width: 120rpx;
							height: 154rpx;
							background-size: cover;

							image {
								margin-top: 34rpx;
								width: 120rpx;
								height: 120rpx;
								border-radius: 60rpx;
							}
						}
					}

					.two {
						display: flex;
						align-items: center;
						flex-direction: column;

						.two_img {
							margin-right: 10rpx;
							margin-top: 70rpx;
							width: 104rpx;
							height: 130rpx;
							background-size: cover;

							image {
								margin-top: 32rpx;
								width: 102rpx;
								height: 102rpx;
								border-radius: 51rpx;
							}
						}
					}

					.three {
						display: flex;
						align-items: center;
						flex-direction: column;

						.three_img {
							margin-left: 18rpx;
							margin-top: 70rpx;
							width: 104rpx;
							height: 130rpx;
							background-size: cover;

							image {
								margin-top: 32rpx;
								width: 102rpx;
								height: 102rpx;
								border-radius: 51rpx;
							}
						}
					}
				}

				.line_view {
					margin: 30rpx 30rpx 4rpx 30rpx;
					height: 1px;
					background: #EBEBEB;
				}

				.rangking_item_view {
					.rangking_item {
						display: flex;
						align-items: center;
						justify-content: space-between;
						padding: 10rpx 40rpx;
					}
				}
			}
		}

		.tools_view {
			margin: 0rpx 30rpx 80rpx 30rpx;
			padding: 30rpx;
			background: #fff;
			border-radius: 16rpx;

			.tool_t {
				font-size: 32rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #303133;
				line-height: 34rpx;
			}

			.tool_content {
				margin-top: 20rpx;
				display: flex;
				flex-wrap: wrap;

				.tool_item {
					display: flex;
					justify-content: center;
					align-items: center;
					flex-direction: column;
					padding: 30rpx 0rpx;
					width: 25%;

					image {
						width: 48rpx;
						height: 48rpx;
					}

					.tool_name {
						margin-top: 16rpx;
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #909399;
						line-height: 24rpx;
					}
				}
			}
		}

		.empty {
			width: 750rpx;
			height: 400rpx;
			margin-top: 200rpx;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;

			image {
				width: 300rpx;
				margin-bottom: 50rpx;
			}

			text {
				font-size: 24rpx;
				font-weight: 600;
			}

			view {
				width: 300rpx;
				height: 70rpx;
				border-radius: 70rpx;
				text-align: center;
				line-height: 70rpx;
				color: #ffffff;
				margin-top: 30rpx;
			}
		}
	}

	.number_name {
		margin-top: 24rpx;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #303133;
		line-height: 40rpx;
	}

	.number_num {
		margin-top: 4rpx;
		font-size: 32rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #855827;
		line-height: 45rpx;
	}
</style>